package com.demo.controller;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName ExceptionController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/16 9:59
 * @Version 1.0
 **/
@ControllerAdvice
public class ExceptionController {
    @ExceptionHandler(value = AuthorizationException.class)
    @ResponseBody
    public String authorizationException() {
        System.out.println("没有权限");
        return "unPermission";
    }

    @ExceptionHandler(value = IncorrectCredentialsException.class)
    @ResponseBody
    public String invalidCredentialsException() {
        return "密码错误";
    }

    @ExceptionHandler(value = UnknownAccountException.class)
    @ResponseBody
    public String unauthorizedCredentialsException() {
        return "账号不存在";
    }
}
